/**
 * Created by user on 2017/11/21.
 */
function AdminChart() {}
AdminChart.LineChart = function(id,options,series){
    var default_opt = {
        credits:{
            enabled:false
        },
        title: {
            text: null
        },
        subtitle: {
            text: null
        },
        yAxis: {
            title:{
                text:null
            },
            lineColor: '#ccc',
            lineWidth:1
        },
        xAxis:{
            lineColor: '#ccc',
            minTickInterval:1,
            tickInterval:1,//刻度间隔为1
            min:0,
            endOnTick:true
        },
        legend: {
            layout: 'horizontal',
            align: 'center'
        },
        tooltip: {
            crosshairs: true,
            shared: true,
            formatter:function () {
                return '<p>' +
                    this.x+'---'+this.y +
                    '小时</p>'
            }
        },
        series: [],
        plotOptions:{
            line:{
                marker: {
                    symbol: 'circle',
                    enabled: true,
                    fillColor: '#fff',
                    height: 10,
                    lineColor:null,
                    lineWidth:1,
                    width:10,
                    states:{
                        hover: {
                            enabled: true,
                            fillColor: '#ecb34a',
                            lineColor: '#fff',
                            lineWidth: 2,
                            lineWidthPlus: 10,
                            // radius: 半径
                            // radiusPlus: 半径增大
                        }
                    }
                }
            },
            area:{
                marker: {
                    symbol: 'circle',
                    enabled: true,
                    fillColor: '#fff',
                    height: 10,
                    lineColor:null,
                    lineWidth:1,
                    width:10,
                    states:{
                        hover: {
                            enabled: true,
                            fillColor: '#ecb34a',
                            lineColor: '#fff',
                            lineWidth: 2,
                            lineWidthPlus: 10,
                            // radius: 半径
                            // radiusPlus: 半径增大
                        }
                    }
                },
                fillColor: {
                    linearGradient: [0, 0, 0, 300],
                    stops: [
                        [0, '#92c360'],
                        [1, Highcharts.Color('#92c360').setOpacity(0).get('rgba')]
                    ]
                }
            }
        }
    };
    var opt = $.extend({}, default_opt, options);
    series && series.length > 0 && (opt.series = series);
    var chart = Highcharts.chart(id, opt);
    return chart;
};
AdminChart.BarChart = function(id,options,series){

};
AdminChart.PieChart = function(id,options,series){

};
AdminChart.CustomCircle = function (id,options, series) {
    var default_opt = {
        chart: {
            type: 'solidgauge',
        },
        credits: {
            enabled: false,
        },
        title: {
            useHTML:true,
            text: '<span style="font-size: 30px;">25%</span> <i class="iconfont icon-rise" style="color:#92c360;font-size: 35px;"></i>',
            floating:true,
            verticalAlign: 'middle',
            y:-10,
        },
        pane: {
            startAngle: 0,
            endAngle: -360,
            background: [{ // Track for Stand
                outerRadius: '50%',
                backgroundColor:'#fff',
                borderWidth: 30

            }]
        },
        yAxis: {
            min: 0,
            max: 100,
            lineWidth: 0,
            tickPositions: []
        },
        tooltip:{
            enabled:false
        },
        plotOptions: {
            solidgauge: {
                borderWidth: 30,
                dataLabels: {
                    enabled: false
                },
                linecap: 'round',
                stickyTracking: false
            }
        },
        series: [{
            name: 'Stand',
            borderColor: {
                linearGradient: { x1: 1,y1: 0, x2: 0,  y2: 1 }, stops: [
                    [0, '#27d5f4'],
                    [1, '#92c360'],
                ]
            },
            data: [{
                radius: '50%',
                innerRadius: '50%',
                y: 0
            }]
        }]
    }
    var opt = $.extend({}, default_opt, options);
    opt
    var chart = Highcharts.chart('chart', default_opt);
    return chart;
};
AdminChart.Utils = (function(){
    function cloneObj(obj){
        var o, obj;
        if (obj.constructor == Object){
            o = new obj.constructor();
        }else{
            o = new obj.constructor(obj.valueOf());
        }
        for(var key in obj){
            if ( o[key] != obj[key] ){
                if ( typeof(obj[key]) == 'object' ){
                    o[key] = cloneObj(obj[key]);
                }else{
                    o[key] = obj[key];
                }
            }
        }
        return o;
    }
    function setZero(m){
        return m<10 ? ('0'+m) : (m+'')
    }
    return {
        cloneObj:cloneObj,
        setZero:setZero
    }
})();